package net.oschina.app.adapter.explore;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import net.oschina.app.R;
import net.oschina.app.base.BaseListAdapter;
import net.oschina.app.bean2.ExploreEventBean;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by 张运湘 on 2017/1/16.
 */

public class RecentlyEventAdapter extends BaseListAdapter<ExploreEventBean.EventBean> {
    private Context mContext;
    //提供一个点击接口
    private FriendsRircleAdapter.setItemOnclickListener mItemOnclickListener=null;
    public void setItemOnclickListener(FriendsRircleAdapter.setItemOnclickListener itemOnclickListener) {
        mItemOnclickListener = itemOnclickListener;
    }

    public interface setItemOnclickListener{
        //跳转到详情页面
        Void toDetilactivity();
    }
    public RecentlyEventAdapter(Context context) {
        mContext = context;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_recentlyeventfragment, parent, false);
        RecyclerView.ViewHolder viewHolder = new recentlyEventHolder(view);
        //点击监听
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mItemOnclickListener!=null){
                    mItemOnclickListener.toDetilactivity();
                }
            }
        });
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ExploreEventBean.EventBean eventBean = mList.get(position);
        //加载图片
       // Glide.with(mContext).load(eventBean.getCover()).into(((recentlyEventHolder)holder).mIvRecentlyEventfragmentItem);

        ((recentlyEventHolder)holder).mTvFragmentRecentlyEventItemDesc.setText(eventBean.getTitle());
        ((recentlyEventHolder)holder).mTvFragmentRecentlyEventItemDesc.setTextSize(16);
        ((recentlyEventHolder)holder).mTvFragmentRecentlyEventItemDesc.setTextColor(Color.BLACK);
        ((recentlyEventHolder)holder).mTvFragmentRecentlyEventItemTime.setText(eventBean.getCreateTime());
        ((recentlyEventHolder)holder).mTvFragmentRecentlyEventItemContent.setText(eventBean.getSpot());

    }

     class recentlyEventHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv_recentlyEventfragment_item)
        ImageView mIvRecentlyEventfragmentItem;
        @BindView(R.id.tv_fragmentRecentlyEvent_item_desc)
        TextView mTvFragmentRecentlyEventItemDesc;
        @BindView(R.id.tv_fragmentRecentlyEvent_item_time)
        TextView mTvFragmentRecentlyEventItemTime;
        @BindView(R.id.tv_fragmentRecentlyEvent_item_content)
        TextView mTvFragmentRecentlyEventItemContent;

        recentlyEventHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
